#include<stdio.h>
#include<string.h>
#include<assert.h>

void* mymemcpy(void* dest, void* src, size_t count) {
	void* ret = dest;
	assert(dest);
	assert(dest);
	while (count--) {
		*(char*)dest = *(char*)src;
		dest = (char*)dest + 1;
		src = (char*)src + 1;
		
	}
	return ret;
}

void* mymemmove(void* dest, void* src, size_t count) {
	void* ret = dest;
	if (dest <= src || (char*)dest >= ((char*)src + count)) {
		while (count--) {
			*(char*)dest = *(char*)src;
			dest = (char*)dest + 1;
			src = (char*)src + 1;
		}
	}
	else {
		dest = (char*)dest + count - 1;
		src = (char*)src + count - 1;
		while (count--) {
			*(char*)dest = *(char*)src;
			dest = (char*)dest - 1;
			src = (char*)src - 1;
		}
	}
	return (ret);
}

int main() {
	/*int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };
	int arr2[10] = { 0 };
	memcpy(arr2, arr1, 20);
	int i = 0;
	for (i = 0; i < 10; i++) {
		printf("%d ", arr2[i]);
	}*/

	/*int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };
	int arr2[10] = { 0 };
	mymemcpy(arr2, arr1, 20);
	int i = 0;
	for (i = 0; i < 10; i++) {
		printf("%d ", arr2[i]);
	}*/

	/*int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
	memmove(arr + 2, arr, 20);
	int i = 0;
	for (i = 0; i < 10; i++) {
		printf("%d ", arr[i]);
	}*/
	int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
	mymemmove(arr + 2, arr, 20);
	int i = 0;
	for (i = 0; i < 10; i++) {
		printf("%d ", arr[i]);
	
	}	
	return 0;
}